package vn.edu.saigontech.ncms.web.receipt;

import vn.edu.saigontech.ncms.service.UserService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateInternalReceiptAction extends AbstractValidator {
	
	private Long id;
	private String date;
	private String name;
	private String fee;
	private Long cashierId;

	@Override
	public String check() {
		if(Checker.isEmpty(date)) {
			this.sendKeyError("validator.required", "date");
		}
		if(!Checker.isDate(this.date, this.i18n("format.date"))) {
			this.sendKeyError("validator.invalid", "date");
		}
		if(Checker.isEmpty(this.name)) {
			this.sendKeyError("validator.required", "name");
		}
		if(Checker.isEmpty(this.fee)) {
			this.sendKeyError("validator.required", "fee");
		}
		if(!Checker.isDouble(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		if(!Checker.isPositive(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		if(Checker.isNull(this.cashierId)) {
			this.sendKeyError("validator.required", "cashier");
		}
		if(Checker.isNull(UserService.INSTANCE.findById(this.cashierId))) {
			this.sendKeyError("validator.notExist", "cashier");
		}
		return this.toSuccess();
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}

	public Long getCashierId() {
		return cashierId;
	}

	public void setCashierId(Long cashierId) {
		this.cashierId = cashierId;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}